import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import RandomUtil from '@/RandomUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/* 月火术 */
export default class DLY_FireOfMoon extends AbilityBase {
    static instance: DLY_FireOfMoon;
    buffType: AppBuffType = {
        id: 'buff_DLY_FireOfMoon',
        art: this.art,
        name: this.abilityName,
        ubertip: '持续受到奥术伤害',
        dur: 12,
        interval: 2,
        onInterval: this.buffInterval.bind(this),
    };
    debuffType: AppBuffType = {
        id: 'buff_DLY_FireOfMoon_debuff',
        art: this.art,
        name: this.abilityName,
        ubertip: '受到的法术伤害增加',
        dur: 6,
        isDebuff: true,
        targetAttach: 'chest',
        targetArt: 'Abilities\\Spells\\Items\\OrbCorruption\\OrbCorruption.mdl',
        stackCountMax: -1,
        attribute: {
            法术伤害减免: -0.15,
        },
    };
    buffInterval(buff: Buff) {
        let source = buff.getCaster();
        let target = buff.getParent();
        let lv = this.getAbilityLevel(source);
        let dmg = 10 * lv + UnitCommon.取法强(source) * (0.3 + 0.2 * lv);
        DamageSystemInstance.applyArcaneDamage(target, source, dmg, this.id, true);
        let r = RandomUtil.randomPercent();
        if (r <= 0.35) {
            BuffCommon.addBuff({
                target,
                caster: source,
                buffTypeId: this.debuffType.id,
                ablityId: this.id,
            });
        }
    }
    constructor(id: string) {
        super(id);
        DLY_FireOfMoon.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
        BuffUtil.registerBuffType(this.debuffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // BuffUtil.addBuff(target, this.buffType.id, source);
        BuffCommon.addBuff({
            target,
            caster: source,
            buffTypeId: this.buffType.id,
            ablityId: this.id,
        });
        DestroyEffect(AddSpecialEffectTarget('月怒\\sem_yue_nu.mdx', target, 'origin'));
        let lv = this.getAbilityLevel(source);
        let dmg = 25 * lv + UnitCommon.取法强(source) * (0.9 + 0.3 * lv);
        DamageSystemInstance.applyArcaneDamage(target, source, dmg, this.id);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
